/**
 *  Copyright (C) 2011  Thomas ROBIN
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package menuitem;

import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import triseries.Main;
import triseries.MyProperties;
import triseries.UnwatchEpisode;

/**
 * @author tshepo
 *
 */
public class MegaUpLink extends JMenuPlugins {
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5785036227185025002L;
	private static String argSearch = MyProperties.configFile.getProperty("MegaUpLink");
	private static boolean episodeItem = true;
	private static boolean display = false;

	/**
	 * 
	 */
	public MegaUpLink(final UnwatchEpisode uwe) {
		super("Recherche MegaUpload");
		
		if(argSearch != null && !argSearch.isEmpty()) display = true;

		this.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
					URI uri = null;
					try {
						uri = new URI(
								"http://www.google.fr/search?q="
										+ (argSearch + " " + uwe.GetUrl() + " " + String
												.format("S%02dE%02d OR %02dx%02d",
														uwe.getSeason(), uwe.getEpisode(), uwe.getSeason(),
														uwe.getEpisode())).replace(" ", "+"));
					} catch (URISyntaxException e1) {
						Main.processExeption("MegaUpLink : "+ e1.getStackTrace().toString());
					}
					try {
						Desktop.getDesktop().browse(uri);
					} catch (IOException e1) {
						Main.processExeption("MegaUpLink : "+ e1.getStackTrace().toString());
					}
			
			}
		});
	}

	/**
	 * @return the display
	 */
	public boolean isDisplay() {
		return display;
	}
	
	/**
	 * @return the episodeItem
	 */
	public boolean isEpisodeItem() {
		return episodeItem;
	}	

}
